package com.example.appbarlayoutdemo.adapter;

import android.graphics.Paint;
import android.graphics.Typeface;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.appbarlayoutdemo.R;
import com.example.appbarlayoutdemo.bean.DataListBean;

import java.util.List;

/**
 * 作者: njb
 * 时间: 2019/5/8 15:57
 * 描述: 热卖商品适配器
 */
public class ShopHotAdapter extends BaseQuickAdapter<DataListBean, BaseViewHolder> {
    private TextView tv_hot_discount,tvPrice;
    private ImageView iv_hot_shop;

    public ShopHotAdapter(@Nullable List<DataListBean> data) {
        super(R.layout.item_new_hot, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, DataListBean item) {
        if (item == null) {
            return;
        }
        iv_hot_shop = helper.getView(R.id.iv_new_shop);
        tv_hot_discount = helper.getView(R.id.tv_new_discount);
        tvPrice = helper.getView(R.id.tv_new_price);
        if (item.getPictureUrl() != null && !item.getPictureUrl().equals("")) {
            //商品图片
            Glide.with(mContext).load(item.getPictureUrl()).into(iv_hot_shop);
        }
        if (item.getSellingPrice() != null && !item.getSellingPrice().equals("")) {
            //商品售价
           tvPrice.setText("￥" + item.getSellingPrice());
        } else {
            tvPrice.setText("");
        }
        if (item.getOfficialPrice() != null && !item.getOfficialPrice().equals("")) {
            //商品原价
            tv_hot_discount.setText("￥" + item.getOfficialPrice());
            tv_hot_discount.getPaint().setAntiAlias(true);//抗锯齿
            tv_hot_discount.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG); //中划线
        } else {
            tv_hot_discount.setText("");
        }
       // Typeface typefacehef = Typeface.createFromAsset(mContext.getAssets(), "Helvetica.ttf");
      //  tvPrice.setTypeface(typefacehef);
       // tv_hot_discount.setTypeface(typefacehef);
    }
}
